package ar.edu.itba.it.raytracer.engine

import scala.Math.min
import java.awt.{ Color => AWTColor }

object Color {
  lazy val white = Color(1, 1, 1)
  lazy val black = Color(0, 0, 0)
  lazy val red = Color(1, 0, 0)
  lazy val green = Color(0, 1, 0)
  lazy val blue = Color(0, 0, 1)
}

case class Color(red: Double, green: Double, blue: Double) {
  require(0 <= red && red <= 1 && 0 <= green && green <= 1 && 0 <= blue && blue <= 1)

  def +(that: Color) = {
    val r = red + that.red; val g = green + that.green; val b = blue + that.blue
    Color(min(r, 1), min(g, 1), min(b, 1))
  }
  
  def *(n: Double) = Color(min(1, red * n), min(1, green * n), min(1, blue * n))
  def *(that: Color) = Color(red * that.red, green * that.green, blue * that.blue)
  override def toString = "(" + red + ", " + green + ", " + blue + ")"
}